package com.dev.cmielke.util;

import org.apache.commons.lang.StringUtils;

public class StringUtilities
{
	public static final String[] IGNORED_WORDS = new String[]{"von", "und", "zu"};
	
	public static String capitalizeWords(String text)
	{
		return capitalizeWords(text, StringUtilities.IGNORED_WORDS);
	}
	
	public static String capitalizeWords(String text, String[] words)
	{
		text = text.toLowerCase();
		String retValue = "";
		
		String[] parts = text.split(" ");
		for (int index = 0; index < parts.length; index++)
		{
			if(!contains(parts[index], words))
			{
				retValue += StringUtils.capitalize(parts[index]);
			}
			else
			{
				retValue += parts[index];
			}
			if(index + 1 < parts.length)
			{
				retValue += " ";
			}
		}
		
		return retValue;
	}
	
	private static boolean contains(String text, String[] words)
	{
		boolean retValue = false;
		
		for (String string : words)
		{
			if(text.contains(string) || text.equals(string))
			{
				retValue = true;
				break;
			}
		}
		
		return retValue;
	}
}
